#define _MAIN_C

#include "globals.h"
#include "alleg.h"
#include "map.h"
#include "enemy.h"
#include "player.h"
#include "menus.h"

void set_globals(void){
    //Init all our global variables ugly ugly ugly
    game_quit=0;
    
    temp_show_rects=0;
    temp_help=0;
    temp_map_number=21;
    temp_music_vol=200;
    temp_sound_vol=255;
    temp_game_mode=0;
    temp_game_difficulty=1;
    temp_player_lives=3;
    temp_enemy_count=5;
    temp_ball_count=1;
    temp_ball_time=1000;
    temp_game_start=0;
    temp_free_life=2000;
    temp_point_adder=0;
    
    liney1=6;
    liney2=74;
    line1x1=151;
    line2x1=152;
    line3x1=153;
    line4x1=154;
    line5x1=155;
    line6x1=156;
    line7x1=496;
    line8x1=497;
    line9x1=498;
    line10x1=499;
    line11x1=500;
    line12x1=501;
    count_levels=1;
    scroll_x1=0;
    scroll_x2=640;
    
    high_score_show=0;
    enemy_velocity=.5;
    enemy_shot_vel=.5;
    ball_velocity=.5;
    player_energy=55;
    player_attack=6;
    enemy_energy=55;
    enemy_attack=1;
      
    show_rects=0;
    help=0;
    map_number=21;
    music_vol=200;
    sound_vol=255;
    game_mode=0;
    game_difficulty=1;
    player_lives=3;
    enemy_count=5;
    ball_count=1;
    ball_time=1000;
    game_start=0;
    free_life=2000;
    point_adder=0;
    temp_enemy_velocity=.5;
    temp_enemy_shot_vel=.5;
    temp_ball_velocity=.5;
    temp_player_energy=55;
    temp_player_attack=6;
    temp_enemy_energy=55;
    temp_enemy_attack=1;

    show_enemy=0;
    show_enemy_time=0;
    
    pausex=rand()%640;pausey=rand()%400;
    pause_speedx=1;pause_speedy=1;pause_wait=rand()%100;
}    

//Our Main thread.....now for some choppin!
int main (void){
    int check_intro=0;
    game_timer=0;
    process=1;
    srand(time(NULL));
    set_color_depth(16);  
    init_all(SCREEN_SIZE_W,SCREEN_SIZE_H);
    maptiles = (DATAFILE *)load_datafile("data/map.dat");
    player_sprites = (DATAFILE *)load_datafile("data/basserk.dat");
    enemy_sprites = (DATAFILE *)load_datafile("data/enemy.dat");
    ball_sprites = (DATAFILE *)load_datafile("data/ball.dat");
    explode_sprites = (DATAFILE *)load_datafile("data/explode.dat");
    game_sound= (DATAFILE *)load_datafile("data/sound.dat");
    status= (DATAFILE *)load_datafile("data/status.dat");
    game_fonts=(DATAFILE *)load_datafile("data/fonts.dat");
    set_globals();
    buffer = create_bitmap(MAP_W*TILE_SIZE,MAP_H*TILE_SIZE);
    menu_buffer = create_bitmap(EDIT_MENU_SIZE_W,EDIT_MENU_SIZE_H);
    init_tiles();
    load_highscore();
    while(!game_quit){
     do_begin(check_intro); 
     if(!game_quit){
         check_intro=do_game();
         if(!check_intro){
             if(draw_highscore())check_intro=1;
         }    
     }    
    }    
    destroy_bitmap( buffer );
    destroy_bitmap( menu_buffer);
    destroy_tiles();
    unload_datafile( maptiles );
    unload_datafile(player_sprites);
    unload_datafile(enemy_sprites);
    unload_datafile(ball_sprites);
    unload_datafile(explode_sprites);
    unload_datafile(game_sound);
    unload_datafile(status);
    unload_datafile(game_fonts);
    return 1;
}
END_OF_MAIN()
